/**
 * 
 */
package com.lazy.lib.entity;

import java.util.HashMap;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lazy.lib.sys.SysContants;

/**
 * 响应信息基础类
 * 
 * @author huangzw
 * 
 */
public class BaseResp extends HashMap<String, Object> {
    private static final long serialVersionUID = -4036551233822181281L;
     
    public BaseResp() {
        this(0, "");
    }
    
    public BaseResp(Integer retCode) {
        setRetCode(retCode);
    }
    
    public BaseResp(Integer retCode, String retMsg) {
        setRetCode(retCode);
        setRetMsg(retMsg);
    }

    public String getToken(){
        return (String) get("token");
    }

    public BaseResp setToken(String token){
        put("token", token);
        return this;
    }

    public Integer getRetCode(){
        return (Integer) get("retCode");
    }

    public BaseResp setRetCode(Integer retCode){
        put("retCode", retCode);
        return this;
    }

    public String getRetMsg(){
        return (String) get("retMsg");
    }

    public BaseResp setRetMsg(String retMsg){
        put("retMsg", retMsg);
        return this;
    }
     
    public boolean emptyData(){
        return true;
    }
    
    @JsonIgnore
    public boolean isFail() {
        return !(isSuccess());
    }
    
    @JsonIgnore
    public boolean isSuccess() {
        Integer retCode = getRetCode();
        return retCode != null && retCode == RETURN_SUCCESS;
    }
    
    public static BaseResp success(){
        return new BaseResp(RETURN_SUCCESS, SysContants.RETURN_SUCCESS_STR);
    }
    
    public static BaseResp success(String retMsg){
        BaseResp resp = success();
        resp.setRetMsg(retMsg);
        return resp;
    }
    
    public static BaseResp fail(Integer retCode, String retMsg){
        return new BaseResp(retCode, retMsg);
    }
    
    public static BaseResp fail(String retMsg){
        return new BaseResp(RETURN_FAILURE, retMsg);
    }
    
    /**操作成功*/
    public static final int RETURN_SUCCESS = SysContants.RETURN_SUCCESS;
    
    /**操作失败*/
    public static final int RETURN_FAILURE = SysContants.RETURN_FAILURE;
    
    /**数据记录不存在：0x00001002*/
    public static final int DATA_NOT_EXIST = SysContants.DATA_NOT_EXIST;
    
    /**返回码：协议参数错误：0x00002001*/
    public static final int RET_CODE_PROTOCOL_ERROR = SysContants.RET_CODE_PROTOCOL_ERROR;
}
